package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.dao.PostageConditionDAO;
import com.junzhiit.nengji.model.PostageCondition;

@Repository
public class PostageConditionDAOImpl extends AbstractBaseDAO<PostageCondition> implements PostageConditionDAO {

	@Override
	public List<PostageCondition> findAll(String postageTemplateId) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		
		sql.append("select * from postage_condition where is_delete=? and postage_template_id=?");
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(postageTemplateId);
		
		return queryForList(sql.toString(), PostageCondition.class, param);
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	@Override
	public boolean updateToDeleteByPostageTemplateId(String postageTemplateId){
		StringBuffer sql=new StringBuffer();
		sql.append("update postage_condition set is_delete=? where postage_template_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setInt(IsDelete.YES.toIntValue());
		param.setString(postageTemplateId);
		
		return super.updateForBoolean(sql.toString(), param);
	}

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	@Override
	public boolean deleteByPostageTemplateId(String postageTemplateId){
		StringBuffer sql=new StringBuffer();
		sql.append("delete from postage_condition where postage_template_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(postageTemplateId);
		
		return super.updateForBoolean(sql.toString(), param);
	}
}
